function BindTree_dept() {
		FindAll_dept(function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var result = mmData.result;
				var data = mmData.resultContent;
				if (result == "1") {
					myTree = new dTree("myTree");
					for (var i = 0; i < data.length; i++) {
						var mmID = data[i].deptid;
						var mmPID = data[i].parentdeptid;
						var mmDeptName = data[i].danweiduiwaimingcheng;
						var mmText = "<span id=" + mmID + ">";
						mmText += "<span style='cursor:pointer;' title=\'"
								+ mmDeptName + "\' onclick=\"SelectDept('"
								+ mmID + "','" + mmDeptName + "');\">" + mmDeptName
								+ "</span>";
						mmText += "</span>";
						if (mmID == "0") {
							myTree.add(mmID, "-1", mmText);
						} else {
							myTree.add(mmID, mmPID, mmText);
						}
					}
					$("#Tree_dept").html("" + myTree);
				}
			}
		});

}

// 增加下级单位
function ToAdd_dept() {
	GetInputAndCheck_dept(function(ppMessage) {
		alert(ppMessage);
	}, function(ppDataObject) {
		Add_dept(ppDataObject, function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var message = mmData.message;
				var result = mmData.result;
				if (result == "1") {
					alert("保存成功");
					BindTree_dept();
					ClearForm_dept();
				} else {
					alert(message);
				}
			}
		});
	});
}
// 修改单位
function ToModify_dept() {
	GetModifyAndCheck_dept(function(ppMessage) {
		alert(ppMessage);
	}, function(ppDataObject) {
		Modify_dept(ppDataObject, function(ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var message = mmData.message;
				var result = mmData.result;
				if (result == "1") {
					alert("修改成功");
					BindTree_dept();
				} else {
					alert(message);
				}
			}
		});
	});
}

// 回显选中单位信息
function BindOldValue_dept() {
	FindOne_dept(CurrentDeptId, function(ppData) {
		if (ppData != null) {
			var mmData = eval(ppData);
			var result = mmData.result;
			var data = mmData.resultContent;
			if (result == "1") {
				ClearForm_dept();
				var mmDeptId = data.deptid;
				mmIsvalid=data.isvalid;

				$("#danweiduiwaimingcheng2").val(data.danweiduiwaimingcheng);
				$("#danweiduineimingcheng2").val(data.danweiduineimingcheng);
				$("#xuliebianma2").val(data.xuliebianma);
				$("#jigoumingchengma2").val(data.jigoumingchengma);
				if (mmIsvalid == "1") {
					$("#newisvalid_dept2").prop({checked:true});
				} else {
					$("#newisvalid_dept2").prop({checked:false});
				}
			}
		}
	});
}
// 检查 单位信息是否规范
function GetInputAndCheck_dept(ppErrorCallback, ppSuccessCallback) {
	var mmDataObject = new Object();
	var mmDeptId = CurrentDeptId;
	var mmIsValid = $("#isvalid_dept").is(":checked") ? "1" : "0";
	var mmDanweimingcheng = $("#danweiduiwaimingcheng").val();
	var mmDanweiduineimingcheng = $("#danweiduineimingcheng").val();
	var mmXuliebianma = $("#xuliebianma").val();
	var mmJigoumingchengnma = $("#jigoumingchengma").val();
	if (mmDanweimingcheng == "") {
		alert("请填写单位名称");
		$("#danweimingcheng").focus();
		return false;
	}
	if (mmXuliebianma == "") {
		alert("请填写序列编码");
		$("#xuliebianma").focus();
		return false;
	}
	if (mmJigoumingchengnma == "") {
		alert("请填写机构名称码");
		$("#jigoumingchengma").focus();
		return false;
	}
	else {
		mmDataObject.deptid = mmDeptId;
		mmDataObject.danweiduiwaimingcheng = mmDanweimingcheng;
		mmDataObject.danweiduineimingcheng = mmDanweiduineimingcheng;
		mmDataObject.xuliebianma = mmXuliebianma;
		mmDataObject.jigoumingchengma = mmJigoumingchengnma;
		mmDataObject.isvalid = mmIsValid;
		ppSuccessCallback(mmDataObject);
	}
}

// 删除选中单位
function Todelete_dept() {
	if (confirm("确定要删除吗？")) {
		layer.closeAll('dialog');
		Delete_dept(CurrentDeptId, function (ppData) {
			if (ppData != null) {
				var mmData = eval(ppData);
				var result = mmData.result;
				var data = mmData.resultContent;
				if (result == "1") {
					alert("删除成功");
					BindTree_dept();
					ActionType = "1";
					SelectDept('0','经商监管');
					//SelectCurrentOfActionType("1");
				} else {
					alert(mmData.message);
					ActionType = "1";
				}
			}
		});

	}else{
		ActionType = "1";
	}

}

//检查修改单位信息
function GetModifyAndCheck_dept(ppErrorCallback, ppSuccessCallback) {
	var mmDataObject = new Object();
	var mmDeptId = CurrentDeptId;
	var mmIsValid = $("#newisvalid_dept2").is(":checked") ? "1" : "0";
	var mmDanweimingcheng = $("#danweiduiwaimingcheng2").val();
	var mmDanweiduineimingcheng = $("#danweiduineimingcheng2").val();
	var mmXuliebianma = $("#xuliebianma2").val();
	var mmJigoumingchengnma = $("#jigoumingchengma2").val();
	if (mmDanweimingcheng == "") {
		alert("请填写单位名称");
		$("#danweiduiwaimingcheng2").focus();
		return false;
	}
	if (mmXuliebianma == "") {
		alert("请填写序列编码");
		$("#xuliebianma2").focus();
		return false;
	}
	if (mmJigoumingchengnma == "") {
		alert("请填写机构名称码");
		$("#jigoumingchengma2").focus();
		return false;
	}
	else {
		mmDataObject.deptid = mmDeptId;
		mmDataObject.danweiduiwaimingcheng = mmDanweimingcheng;
		mmDataObject.danweiduineimingcheng = mmDanweiduineimingcheng;
		mmDataObject.xuliebianma = mmXuliebianma;
		mmDataObject.jigoumingchengma = mmJigoumingchengnma;
		mmDataObject.isvalid = mmIsValid;
		ppSuccessCallback(mmDataObject);
	}
}
// 清空单位信息
function ClearForm_dept() {
	$("#danweimingcheng").val("");
	$("#shifouyouxiao_dept").checked=false;
}
function GetInputAndCheck_Admin(ppErrorCallback, ppSuccessCallback) {
	var mmDataObject = new Object();

	var mmAdminId = $("#adminid").val();
	var mmLoginname = $("#loginname").val();
	var mmLoginpassword = $("#loginpassword").val();
	var mmTruename = $("#truename").val();
	var mmPhone = $("#phone").val();
	var mmAdmintype = $("#admintype").is(":checked") ? "2" : "3";
	var mmIsvalid = $("#isvalid").is(":checked") ? "1" : "0";

	if (mmLoginname == "") {
		alert("请填写登录账号");
		$("#loginname").focus();
		return false;
	}
	if (mmLoginpassword == "") {
		alert("请填写密码");
		return false;
	}
	if (mmTruename == "") {
		alert("请填写姓名");
		return false;
	}

	mmDataObject.deptid = CurrentDeptId;
	mmDataObject.adminid = mmAdminId;
	mmDataObject.loginname = mmLoginname;
	mmDataObject.loginpassword = mmLoginpassword;
	mmDataObject.truename = mmTruename;
	mmDataObject.phone = mmPhone;
	mmDataObject.admintype = mmAdmintype;
	mmDataObject.isvalid = mmIsvalid;
	ppSuccessCallback(mmDataObject);
}